<template>
	<view class="container">
		<view class="header-search-input">
			<view class="searchInput">
				<image src="@/static/image/password/icon.png" class="left" />
				<input v-model="oldPassword" type="password" placeholder="请输入旧密码" placeholder-class="placeholder"
					@input="veri">
			</view>
			<view class="searchInput">
				<image src="@/static/image/password/lock.png" class="left" />
				<input v-model="newPassword" type="password" placeholder="请输入新密码" placeholder-class="placeholder"
					@input="veri">
			</view>
			<view class="searchInput">
				<image src="@/static/image/password/lock-new.png" class="left" />
				<input v-model="comNewPassword" type="password" placeholder="请再次输入新密码" placeholder-class="placeholder"
					@input="veri">
			</view>
			<view class="loginMethods">
				<button v-if="sumit" class="login" @click="toLogin">确认修改</button>
				<button v-else class="login1" :disabled="true">确认修改</button>
			</view>
		</view>
	</view>

</template>
<script>
	import {
		updatePwd
	} from '@/api/login.js'
	export default {
		data() {
			return {
				sumit: false,
				show: true,
				oldPassword: '',
				comNewPassword: '',
				newPassword: '',
				isShow: false,
				method: 'h5'
			}
		},
		mounted() {

		},
		methods: {
			veri() {
				if (this.oldPassword.trim() && this.newPassword.trim() && this.comNewPassword.trim()) {
					this.sumit = true
				} else {
					this.sumit = false
				}
			},
			async toLogin() {


				const {
					oldPassword,
					newPassword,
					comNewPassword
				} = this
				if (newPassword !== comNewPassword) {
					uni.showToast({
						icon: 'none',
						title: '确认密码两次不一致',
						duration: 3000,
					})
					return
				}
				uni.showLoading({
					title: '加载中'
				})
				this.sumit = false
				let result = await updatePwd({
					oldPassword,
					newPassword
				})
				if (result && result.code === 200) {
					uni.hideLoading()
					uni.showToast({
						icon: 'none',
						title: '修改成功请重新登录',
						duration: 2000,
					})
					setTimeout(() => {
						this.sumit = true
						uni.redirectTo({
							url: '/subPages/login/index',
							success: res => {
								uni.clearStorageSync();
							}
						});
					}, 2000)

				} else {
					uni.hideLoading()
				}

			}
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		// width: 100vw;
		padding: 30rpx;

		.logo {
			padding-top: 194rpx;
			display: flex;
			margin-bottom: 109rpx;

			image {
				width: 481rpx;
				height: 84rpx;
			}
		}

		.header-search-input {
			padding: 0 26rpx;

			.searchInput {
				position: relative;
				height: 100rpx;
				width: 578rpx;
				border-radius: 51rpx;
				border: 1rpx solid #D8D8D8;
				padding: 0 30rpx;
				display: flex;
				align-items: center;
				margin-bottom: 30rpx;


				.left {
					position: absolute;
					left: 19rpx;
					top: 30rpx;
					width: 38rpx;
					height: 38rpx;
				}

				input {
					font-size: 28rpx;
					margin-left: 50rpx;
					padding-left: 20rpx;
					height: 56rpx;
					color: #222;
				}

				.placeholder {
					font-size: 28rpx;
					color: #AAAAAA;
				}
			}

		}


		.loginMethods {
			padding-top: 60rpx;
			font-size: 30rpx;

			.login {
				width: 638rpx;
				height: 100rpx;
				background: #2E73EA;
				border-radius: 51rpx;
				line-height: 100rpx;
				color: #fff;
				border: none;
			}

			.login::after {
				border: none;
			}

			.login1 {
				width: 638rpx;
				height: 100rpx;
				background: #2E73EA;
				border-radius: 51rpx;
				line-height: 100rpx;
				color: #fff;
				border: none;
				opacity: 0.5;

			}

			.login1::after {
				border: none;
			}
		}


		.wxlogin {
			padding-top: 24rpx;
			margin: 0 auto;
			width: 70rpx;
			text-align: center;

			img {
				width: 70rpx;
				height: 70rpx;
			}

			span {
				font-size: 24rpx;
				color: #8b8b8b;
			}
		}

	}
</style>
